import type {
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DoctorPage,
  FollowType,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  TopDep,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'
import { request } from '@/utils/request'
// 获取文章列表
export const getKnowledgePage = (data: KnowledgeParams) =>
  request<KnowledgePage>('patient/home/knowledge', 'get', data)
// 获取医生列表
export const getDoctorPage = (data: PageParams) =>
  request<DoctorPage>('home/page/doc', 'get', data)

// 关注操作
export const followOrUnfollow = (data: { type: FollowType; id: string }) =>
  request('like', 'post', data)

// 获取所有科室
export const getAllDep = () => request<TopDep[]>('dep/all')

// 上传图片
export const uploaImg = (file: File) => {
  const fm = new FormData()
  fm.append('file', file) // 处理数据为formData类型
  return request<{ id: string; url: string }>('upload', 'post', fm)
}

// 计算就诊信息和抵扣信息
export const getConsultOrderPre = (data: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('patient/consult/order/pre', 'get', data)

// 生成订单id
export const createConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('patient/consult/order', 'post', data)

// 携带支付方式+订到id+回跳地址 得到支付的地址
export const getConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1 | undefined
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'post', data)

// 获取订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'get', { orderId })

// 未读消息列表
export const getUnReaList = () => request<number>('/patient/message/unRead/all')

// 获取处方详情
export const getPreInfo = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`)

// 评价医生
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request('patient/order/evaluate', 'post', data)

// 获取问诊记录

export const getConsultOrderList = (data: ConsultOrderListParams) =>
  request<ConsultOrderPage>('patient/consult/order/list', 'GET', data)

// 取消问诊
export const cancelOrder = (id: string) =>
  request(`patient/order/cancel/${id}`, 'put')

//删除订单
export const delOrder = (id: string) => request(`patient/order/${id}`, 'delete')
